package com.workflowengine.event.support;

import com.google.gson.Gson;
import com.workflowengine.event.workflowevent.events.*;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

/**
 * @Package: com.workflowengine.event.support
 * @ClassName: WorkFlowLister
 * @Author: h2cloud
 * @CreateTime: 2024/7/15 10:45 下午
 * @Description:
 */
@Component
@Log4j2
public class WorkFlowListener {

	@Autowired
	public Gson gson;

	public void handleCommonLogic(AbstractEvent event) {
		log.info("handleCommonLogic:{}", gson.toJson(event.getContent()));
	}

	@EventListener
	public void WorkFlowStartEventListener(WorkFlowStartEvent event) {
		log.info("WorkFlowStartEventListener...");
		handleCommonLogic(event);
	}

	@EventListener
	public void WorkFlowEndEventListener(WorkFlowEndEvent event) {
		log.info("WorkFlowEndEventListener...");
		handleCommonLogic(event);
	}

	@EventListener
	public void WorkFlowCancelEventListener(WorkFlowCancelEvent event) {
		log.info("WorkFlowCancelEventListener...");
		handleCommonLogic(event);
	}

	@EventListener
	public void WorkFlowRevokeEventListener(WorkFlowRevokeEvent event) {
		log.info("WorkFlowRevokeEventListener...");
		handleCommonLogic(event);
	}

	@EventListener
	public void NodeStartEventListener(NodeStartEvent event) {
		log.info("NodeStartEventListener...");
		handleCommonLogic(event);
	}

	@EventListener
	public void NodeEndEventListener(NodeEndEvent event) {
		log.info("NodeEndEventListener...");
		handleCommonLogic(event);
	}
}
